package com.login.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Component
public class LoginCheckInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request,
											HttpServletResponse response,
											Object handler)throws Exception{
		
		HttpSession session = request.getSession();
		
		if(session.getAttribute("userId")==null){
			response.sendRedirect("main.do");
			return false;
		}
		
		return true;
	}
}
